package com.neuedu.collection.List;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList  list = new ArrayList();
        list.add("加利");
        list.add("安南");
        list.add("特朗普");
        list.add("拜登");
        System.out.println(list);
        list.add(3,"安倍");
        System.out.println(list);
        System.out.println(list.get(1));
        list.remove(3);
        System.out.println(list);
        list.remove("安南");
        System.out.println(list);
        User  u1 = new User("123","456");
        User  u2 = new User("123","456");
        list.add(u1);
        list.add(u2);
        list.remove(u1);
        System.out.println(list);
        int index = list.indexOf("拜登媳妇");
        System.out.println(index);
        list.add(3,"特朗普");
        System.out.println(list);
        int lastIndex= list.lastIndexOf("特朗普");
        System.out.println(lastIndex);

        list.set(3,"川普");
        System.out.println(list);

        for(Iterator  it = list.iterator(); it.hasNext();){
            System.out.println(it.next());
        }
        System.out.println("==========================");
        for(Iterator  it = list.listIterator(); it.hasNext();){
            System.out.println(it.next());
        }
        System.out.println("==========================");
        for(Object  o : list){
            System.out.println(o);
        }


        List myList = new ArrayList();
        myList.add(1);
        myList.add(2);

        System.out.println("myList.get(0).getClass() = " + myList.get(0).getClass());

        //逻辑上 需求 要求存储名字列表 , 编译的时候生效
        List<String> namesList = new ArrayList();
        namesList.add("张飞1");
        namesList.add("张飞2");
//        namesList.add(100);
    }
}
